﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.baseBLL;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.orderDAL;

namespace dhSystemBLL.orderData
{
   public  class pbomDetailBLL
    {
        private pbomDetailTableAdapter _pbomDetailAdapter = null;
        private pbomDetailTableAdapter pbomDetailAdapter
        {
            get
            {
                if (_pbomDetailAdapter == null) _pbomDetailAdapter = new pbomDetailTableAdapter();
                return _pbomDetailAdapter;
            }
        }
        /// <summary>
        /// 根据产品名称查询产品BOM从表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public orderDataSet.pbomDetailDataTable getpbomDetailbypanmeAll(string name)
        {
            try
            {
                return pbomDetailAdapter.GetDatapbomDeailByname (name);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 查询产品BOM从表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public orderDataSet.pbomDetailDataTable getpbomDetailAll()
        {
            try
            {
                return pbomDetailAdapter.GetDatapbomDetailAll();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 根据原材料名称查询产品BOM从表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public orderDataSet.pbomDetailDataTable getpbomDetailAllBypnamelike(string pname)
        {
            try
            {
                return pbomDetailAdapter.GetDatapbomDetailBypnamelike (pname);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 插入产品BOM从表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public int pbomDetailInsert(pbomDetailModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pbomDetailDAL pbomDetail = new pbomDetailDAL(tn, conn);
                pbomDetail.pbomDetailInsert(row);
                tn.Commit();
                return i;

            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
                
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新产品BOM从表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public int pbomDetailUpdate(pbomDetailModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pbomDetailDAL pbomDetail = new pbomDetailDAL(tn, conn);
                pbomDetail.pbomDetailUpdate(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
                
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除一行产品BOM从表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public int pbomDetailDel(string matNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pbomDetailDAL pbomDetail = new pbomDetailDAL(tn, conn);
                pbomDetail.pbomDetailDel(matNum);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
               
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
